<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="./css/common.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/icon.css"/>
		<title>风机检查详情</title>
		<style type="text/css">
			.mui-table-view-cell>a:not(.mui-btn) {
				padding: 10px 15px;
			}
			.mui-table-view-cell.mui-collapse .mui-collapse-content {
				margin-top: 0;
			}
			.mui-table-view-cell.mui-collapse {
				background-color: #FFFFFF;
			}
			.between {
				-webkit-justify-content: space-between;
				justify-content: space-between;
			}
			.label {
				color: #808080;
			}
			.thumb {
				position: relative;
				width: 80px;
				height: 80px;
				margin: 5px;
			}
			.thumb img {
				width: 100%;
				height: 100%;
			}
			.thumb .action-delete {
				position: absolute;
				left: 0;
				right: 0;
				bottom: 0;
				background-color: rgba(0, 0, 0, 0.5);
				text-align: center;
			}
			.action-delete .mui-icon {
				color: #FFFFFF;
			}
			.flex-wrap {
				-ms-flex-wrap: wrap;
				-webkit-flex-wrap: wrap;
				flex-wrap: wrap;
				align-items: flex-end;
			}
			.add-pic {
				-webkit-justify-content: center;
				justify-content: center;
				border: 1px dashed #DDDDDD;
				color: #DCDCDC;
			}
			.add-pic .mui-icon {
				font-size: 40px;
			}
			.check-item-record {
				padding: 5px 0;
				border-bottom: 1px solid #ECECEC;
			}
			.check-item-record textarea {
				font-size: 14px;
				padding-left: 0;
			}
			.check-item-record .icon-down {
				color: #00A0E8;
			}
			.collapse-title {
				position: relative;
				line-height: 16px;
				padding-left: 12px;
				padding-right: 5px;
				color: #000000;
				white-space: normal!important;
			}
			.collapse-title:before {
				content: "";
				position: absolute;
				left: 0;
				top: 0;
				width: 2px;
				height: 15px;
				background-color: #FA8100;
			}
			.mui-bar-tab .mui-tab-item {
				font-size: 14px;
				color: #004A86;
			}
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #004A86;
			}
			.mui-bar-tab .mui-tab-item .mui-icon {
				width: 28px;
			}
			.mui-bar-tab .mui-tab-item .mui-icon:active {
				opacity: 1;
			}
			.mui-switch {
				width: 85px;
			}
			.mui-switch:before {
				content: "不合格";
			}
			.mui-switch.mui-active:before {
				content: "合格";
			}
			.mui-switch.mui-active .mui-switch-handle {
				-webkit-transform: translate(54px,0);
				transform: translate(54px,0);
			}
			[contenteditable=true] {
			  position: relative;
			  -webkit-user-modify: read-write-plaintext-only;
			}
			[contenteditable=true]:empty:before {
			  content: attr(placeholder);
			  position: absolute;
			  left: 0;
			  right: 0;
			  top: 5px;
			  margin: auto;
			  color: #999;
			}
			.alike-textarea {
				-webkit-user-select:text;
				padding-top: 5px;
				word-break: break-all
			}
			.mui-select {
				width: 100px;
			}
			.mui-select:before {
				font-family: "iconfont" !important;
				position: absolute;
				top: 8px;
				right: 10px;
				content: "\e650";
				color: #00A0E8;
			}
			.required {
				position: relative;
			}
			.required:before {
				position: absolute;
				left: -5px;
				top: 10px;
				content: "*";
				color: #f56c6c;
			}
			.required-image {
				font-size: 13px;
				color: #f56c6c;
			}
			.mui-checkbox.mui-left label, .mui-radio.mui-left label {
				padding-right: 5px;
				padding-left: 54px;
			}
      .overflow{
        overflow: hidden;
        vertical-align: middle;
      }
      .overflow span{
        /* float: left; */
        vertical-align: middle;
      }
      .actualInput{
       width: 100px !important;
        border: 0px !important;
        border-bottom: 1px solid #ccc !important;
        margin-bottom: 0 !important;
        padding: 0 !important;
        text-align: center;
        font-size: 15px;
        vertical-align: middle;
        margin: 0 10px
      }
      .inline{
        /* display: inline; */
        -webkit-user-select:text
      }
		</style>
	</head>
	<body>
		<div id="container">
			<header class="mui-bar mui-bar-nav">
				<h1 class="mui-title">{{ title }}</h1>
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
				<a id="fold" class="mui-pull-right header-right">{{ isExpand ? '全部折叠' : '全部展开' }}</a>
			</header>
			<footer class="mui-bar mui-bar-tab">
				<a id="save" class="mui-tab-item mui-text-center">
					<span class="mui-icon"><img class="home_icon" src="../../img/save.png" width="28" /></span>
					<span class="mui-tab-label">保存</span>
				</a>
				<a id="up" class="mui-tab-item mui-text-center">
					<span class="mui-icon"><img class="home_icon" src="../../img/post.png" width="28" /></span>
					<span class="mui-tab-label">提交</span>
				</a>
			</footer>
			<div id="scroll" class="mui-content mui-scroll-wrapper" :style="{height: height + 'px'}">
				<div class="mui-scroll">
					<ul class="mui-table-view"> 
						<li class="mui-table-view-cell mui-collapse mui-active" v-for="(item, index) in checkDetails" :key="index">
							<a class="mui-navigate-right" href="#">
								<div class="collapse-title">{{ item.serial_number }} {{ item.content }}</div>
							</a>
							<div class="mui-collapse-content">
								<div class="flex-center between check-item-record">
									<span class="label">状态</span>
									<div v-for="option in options" class="mui-input-row mui-radio mui-left">
										<label>{{ option.label }}</label>
										<input type="radio" :value="option.value" v-model="item.status">
									</div>
								</div>
								<div class="check-item-record" v-if="item.standard_value">
                  <div v-if="item.standard_value_type===1">标准值={{item.standard_value}}</div>
                  <div v-if="item.standard_value_type===2">标准值&lt;{{item.standard_value}}</div>
                  <div v-if="item.standard_value_type===3">标准值&gt;{{item.standard_value}}</div>
                  <div v-if="item.standard_value_type===4">{{item.standard_value[0]}}&lt;标准值&lt;{{item.standard_value[1]}}</div>
									<!-- <span class="label"v-if="item.standard_value_type===4">实际值(单位 {{item.standard_value[0]|toUnit}})</span>									 -->
									<!-- <textarea style="border: 0;margin-bottom: 0;padding: 10px 0 0;" rows="2" placeholder="请输入"></textarea> -->
                  <div class="alike-textarea overflow"><span class="label">实际值</span><input type="number"v-if="inputType==='ios'" v-model="item.actual"onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"@blur="handleInput(index)"placeholder="请输入"class="actualInput"/><input type="tel"v-else v-model="item.actual"onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"@blur="handleInput(index)"placeholder="请输入"class="actualInput"/><span class="label"v-if="item.standard_value_type===4">{{item.standard_value[0]|toUnit}}</span><span class="label"v-else>{{item.standard_value|toUnit}}</span></div>
								</div>
                <div class="check-item-record"v-if="item.data_record">
									<span class="label">记录</span>
									<!-- <textarea style="border: 0;margin-bottom: 0;padding: 10px 0 0;" rows="2" placeholder="请输入"></textarea> -->
									<div v-if="item.hasBrackets" :id="'item' + item.serial_number" class="alike-textarea" v-html="item.data_record"></div>
									<div v-else :id="'item' + item.serial_number" class="alike-textarea" v-html="item.data_record" contenteditable="true" placeholder="请输入"></div>
								</div>
								<div class="check-item-record">
									<span class="label">备注</span>
									<!-- <textarea style="border: 0;" rows="2" placeholder="请输入"></textarea> -->
									<div class="alike-textarea" v-html="item.remarks" @blur="item.remarks = $event.target.innerText" contenteditable="true" placeholder="请输入"></div>
								</div>
								<div class="flex-center flex-wrap pt-10" :class="{ required: item.is_photograph == 1 }"><!-- v-if="item.is_photograph === 1"  -->
									<div class="thumb" v-for="(ele, i) in item.images" :key="i">
										<img :src="ele" >
										<div class="action-delete" @tap="deleteImg(item, index, i)">
											<span class="mui-icon mui-icon-trash"></span>
										</div>
									</div>
									<div v-if="item.images.length === 0" class="thumb add-pic flex-center" @tap="addPic(index)"><span class="mui-icon mui-icon-camera"></span></div>
									<span v-if="item.is_photograph == 1" class="required-image">（此项要求图片必传）</span>
								</div>
							</div>
						</li>
					</ul>
				</div>
			</div>
		</div>
		
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/vue.js"></script>
		<script src="../../js/common.js"></script>
		<script src="../../js/mkeyplus.base.js"></script>
		<script src="../../js/storage.js"></script>
		<script src="../../js/uuid.js"></script>
		<script src="./js/uploadImage.js"></script>
		<script type="text/javascript">
			(function($) {
				var netStatus = null; // 网络状态
				var detailVM = null; // 实例
				var cv = null; // 当前webview
				var blowerId = null; // 风机id
				var itemId = null; // 检查大项id
				var templateData = []; // 模板数据
				var managerId = ''; // 负责人id
				var groupIds = ''; // 班组人员id
				var netStatus = null; // 网络状态
				var type = null; // 0 半年检 1 一年检
				var templateId = null; // 所使用的模板id
				var latestTime = ''; // 最晚定检时间
				var userId = localStorage.getItem('userid'); // 当前登陆的user
				
				$.init();
				
				detailVM = new Vue({
					el: '#container',
					data: {
            inputType:'tel',
						title: '',
						height: 0, // 人员列表高度
						currentIndex: 0,
						checkDetails: [{
							data_record: '',
							state: 1,
							remarks: '',
              actual:'',
							images: [] // 图片列表
						}, {
							data_record: '',
							state: 0,
							remarks: '',
              actual:'',
							images: [] // 图片列表
						}], // 具体检查项列表
						options: [
							{ label: '正常', value: 0 },
							{ label: '异常', value: 1 },
							{ label: '不适用', value: 2 }
						],
						isExpand: true // 是否全部展开
					},
          filters:{//局部过滤器   			
            toChies:function(str){//形参
              var ary = [];
              var num = "";
              var unit = "";
              for(var i=0;i<str.length;i++){
                  if(str.charAt(i) >= "0" && str.charAt(i) <= "9"){
                      num += str.charAt(i)
                  }else{
                      unit += str.charAt(i)
                  }
              }
              return num;
            },
            toUnit:function(str){//形参
              var ary = [];
              var num = "";
              var unit = "";
              for(var i=0;i<str.length;i++){
                  if(str.charAt(i) >= "0" && str.charAt(i) <= "9"){
                      num += str.charAt(i)
                  }else{
                      unit += str.charAt(i)
                  }
              }
              return unit;
            } 
                       
          },
					created:function() {
						this.initHeight()
					},
					methods: {
						// 设置高度
						initHeight: function() {
							this.height = window.innerHeight;
						},
            handleInput(index) {
               var that=this              
              if(that.checkDetails[index].standard_value_type===1){
                var stard=that.$options.filters['toChies'](that.checkDetails[index].standard_value)
                if(Number(stard)==Number(that.checkDetails[index].actual)){
                 that.checkDetails[index].status="0"
                }else{
                  that.checkDetails[index].status="1"
                }
              }
              if(that.checkDetails[index].standard_value_type===2){
                var stard=that.$options.filters['toChies'](that.checkDetails[index].standard_value)
                if(Number(stard)>Number(that.checkDetails[index].actual)){
                 that.checkDetails[index].status="0"
                }else{
                  that.checkDetails[index].status="1"
                }
              }
              if(that.checkDetails[index].standard_value_type===3){
                var stard=that.$options.filters['toChies'](that.checkDetails[index].standard_value)
                if(Number(stard)<Number(that.checkDetails[index].actual)){
                 that.checkDetails[index].status="0"
                }else{
                  that.checkDetails[index].status="1"
                }
              }
              if(that.checkDetails[index].standard_value_type===4){
                var stard=that.$options.filters['toChies'](that.checkDetails[index].standard_value[0])
                var stard1=that.$options.filters['toChies'](that.checkDetails[index].standard_value[1])
                if(Number(stard)<Number(that.checkDetails[index].actual)&&Number(stard1)>Number(that.checkDetails[index].actual)){
                  console.log(stard+stard1)
                 that.checkDetails[index].status="0"
                }else{
                  that.checkDetails[index].status="1"
                }
              }
            },
						// 添加图片
						addPic: function(index) {
							var that = this;
							page.imgUp(function(path) {
								console.log('compress image path: ' + path)
								var images = that.checkDetails[index].images;
								images.push(path);
								that.$set(that.checkDetails[index], 'images', images);
							});
						},
						// 删除图片
						deleteImg(item, index, i) {
							var that = this;
							$.confirm('确定要删除此图片吗？', '提示', ['取消', '确认'], function (e) {
								console.log(e.index)
								if (e.index === 1) { // 确认
									var images = that.checkDetails[index].images;
									images.splice(i, 1);
									that.$set(that.checkDetails[index], 'images', images);
								} else {
									console.log('取消删除')
								}
							}, 'div');
						}/* ,
						// 切换
						toggleSwitch: function(e, index) {
							this.$set(this.checkDetails[index], 'state', +e.detail.isActive)
						} */
					}
				});
				
				$('#scroll').scroll({
					indicators: false //是否显示滚动条
				});
				
				$.plusReady(function() {
          if(mui.os.ios){
            
            detailVM.inputType='ios'
          }else{
          	detailVM.inputType='Android'
          }
					netStatus = plus.networkinfo.getCurrentType();
					cv = plus.webview.currentWebview();
					detailVM.title = cv.sb_name;
					blowerId = cv.blowerId; // 风机id
					itemId = cv.itemId; // 大项id
					managerId = cv.managerId; // 负责人id
					groupIds = cv.groupIds; // 班组人员id
					type = cv.type; // 年检频率
					templateId = cv.templateId; // 所使用的模板id
					latestTime = cv.latestTime;
					templateData = JSON.parse(cv.templateData); // 设备检查项数据
					console.log(templateData)
					var reg = /（.*?）/g;
					detailVM.checkDetails = templateData.map(function(ele) {
						if (!('status' in ele)) {
							ele.status = '' // 默认未检查状态
						}
						if (!('images' in ele)) {
							ele.images = []
						}
            if (!('actual' in ele)) {
							ele.actual = ''
						}
						if (ele.data_record && ele.data_record.indexOf('（') > -1) {
							var tempRecordArr = ele.data_record.match(reg);
							$.each(tempRecordArr, function(index, record) {
								var c = record.replace(/[（）]/g, '');
								ele.data_record = ele.data_record.replace(new RegExp(record, 'g'), '<span class="inline">（</span><span contenteditable="true"class="inline numText">&nbsp;&nbsp; ' + c + '&nbsp;&nbsp;</span><span class="inline">）</span>')
							})
							ele.hasBrackets = true
						}
            if(ele.standard_value_type===4){
              ele.standard_value=ele.standard_value.split(';')
            }
            if (!('actual_unit' in ele)) {
              ele.actual_unit=''
              if(ele.standard_value_type===4) {
                ele.actual_unit = unit(ele.standard_value[0])
              }else if(ele.standard_value_type===1||ele.standard_value_type===2||ele.standard_value_type===3){
                ele.actual_unit = unit(ele.standard_value)
              }             
            }
						return ele
					});
				});
				function unit(str){//形参
          var ary = [];
          var num = "";
          var unit = "";
          for(var i=0;i<str.length;i++){
              if(str.charAt(i) >= "0" && str.charAt(i) <= "9"){
                  num += str.charAt(i)
              }else{
                  unit += str.charAt(i)
              }
          }
          return unit;
        }
				// 提交或保存后更新从草稿箱及待定检里列表数据
				function updateListData() {
					var list = plus.webview.getWebviewById('../regularCheck/index.html');
					$.fire(list,'updateWillcheckAndDraft', {
						id: blowerId
					});
				}
				// 调整草稿箱中大项状态status
				function updateSubmitStatus() {
					var storageDraftList = myStorage.getItem('blowerDraftList') || [];
					var curBlower = storageDraftList.filter(function(ele) {
						return ele.id == blowerId;
					})[0];
					var curItem = curBlower.categoryList.filter(function(ele) {
						return ele.id == itemId;
					})[0];
					curItem.status = 3;
					myStorage.setItem('blowerDraftList', storageDraftList);
				}
				// 提交请求
				function handleSubmit(options) {
          console.log('提交数据+++++++'+JSON.stringify(options))
					var list = options.map(function(ele) {
						/* if (ele.is_photograph && !ele.uploadImagePath) {
							$.toast(ele.serial_number + ' 项图片上传失败，请稍后重新提交', { type: 'div' })
						} */
						return {
							id: ele.id,
							data_record: ele.data_record || '',
							desc: ele.remarks || '',
							image: ele.uploadImagePath || '',
							check_user: userId,
							status: ele.status,
              actual_value:ele.actual,
              actual_unit:ele.actual_unit
						}
					})
					var params = {
						id: blowerId,
						checkInfo: JSON.stringify(list),
						job_manager:managerId,
						group_user: groupIds
					}
					var wt = plus.nativeUI.showWaiting('正在提交...');
					$.baseApp.httpRequst('/api/v2/inspection/submitCheckPointInfo', params,
						function(res) {
							wt.close();
							console.log("提交定检设备：" + JSON.stringify(res));
							if (res.status === 200) {
								$.toast(res.message, { type: 'div' });
								// 更新草稿箱中此大项为status 3 代表提交过
								updateSubmitStatus();
								// 更新前一个页面的状态
								var opener = cv.opener();
								$.fire(opener, 'refreshList', {
									id: itemId,
									status: 3
								});
								updateListData(); // 更新列表页状态
								cv.close(); // 关闭当前页
							} else {
                
								$.toast(res.message, { type: 'div' })
							}
						},
						function(err) {
							wt.close();
							console.log(err)
						},
						'post'
					);
				}
				
				// 保存到本地
				function handleSave2Local(options, cb) {
					var storageBlowerDraftList = myStorage.getItem('blowerDraftList') || [];
					var members = myStorage.getItem('checkMembers') || [];
					var allChecked = options.every(function(ele) {
						return ele.status !== ''
					});
					// 只要有一个需要提交图片但是还没有添加图片
					var allImagesChecked = options.some(function(ele) {
						return ele.is_photograph && ele.images.length === 0;
					});
					var itemData = {
						id: itemId, // 大项id
						checkinfo: options,
						status: allImagesChecked ? 1 : (allChecked ? 2 : 1) // 自定义大项检查完成状态 1 完成部分检查或未检查点击保存到本地, 2 完成c所有
					}
					var jobManager = members.filter(function(ele) {
						return ele.id == managerId;
					});
					var blowerData = {
						userId: userId,
						id: blowerId, // 风机id
						managerId: managerId, // 风机负责人id
						jobManager: jobManager.length ? jobManager[0].name : '', // 负责人名字
						groupIds: groupIds, // 风机班组成员
						type: type, // 年检频率
						templateId: templateId,
						latestTime: latestTime,
						sbName: detailVM.title, // 风机编号
						categoryList: [itemData]
					}
					if (storageBlowerDraftList.length) {
						// 查找草稿箱有无当前风机
						var filterBlower = storageBlowerDraftList.filter(function(ele) {
							return ele.id == blowerId && ele.userId == userId;
						})
						if (filterBlower.length) {
							var currentBlower = filterBlower[0];
							var j = 0; // 相等的索引
							var currentItem = currentBlower.categoryList.filter(function(ele, i) {
								if (ele.id == itemId) {
									j = i;
								}
								return ele.id == itemId
							});
							if (currentItem.length) { // 替换掉大项的数据
								currentBlower.categoryList.splice(j, 1, itemData);
							} else {
								currentBlower.categoryList.push(itemData);
							}
						} else {
							storageBlowerDraftList.push(blowerData);
						}
					} else {
						storageBlowerDraftList = [blowerData];
					}
					myStorage.setItem('blowerDraftList', storageBlowerDraftList)
					// $.toast('本地保存成功', { type: 'div' });
					if (cb && typeof cb === 'function') {
						cb();
					}
				}
				
				// 提交 验证
				document.getElementById('up').addEventListener('tap', function() {
					var details = JSON.parse(JSON.stringify(detailVM.checkDetails))					
					var maxIndex = 0;
					var check = true;
          var num='';
          var isWrite=false;
          $.each(details, function(i, ele) {
            if(!ele.data_record){
              return
            }
          	var qid = 'item' + ele.serial_number;
          	var dom = document.getElementById(qid)
            var numText = dom.getElementsByClassName('numText');
            for (var j = 0; j < numText.length; j++) {           
              var text=numText[j].innerText;
              text=text.replace(/\s/g,"");
               if(text==''){
                 isWrite=true;
                 num=ele.serial_number;
                 return;
               }
            }
          });
          $.each(details, function(i, ele) {
            if(ele.data_record){
              var qid = 'item' + ele.serial_number;
              var dom = document.getElementById(qid)
              ele.data_record = dom.innerText;             
            }
          	if(ele.standard_value_type===4){
          	  ele.standard_value=ele.standard_value.join(';')
          	}
          });
					for (var i = 0; i < details.length; i++) {
						var ele = details[i];
            if (ele.standard_value && ele.actual=='') {
            	$.toast(ele.serial_number + ' 项还未填写相应实际值', { type: 'div' });
            	check = false;
            	break;
            } 
						if (ele.status === '') {
							$.toast(ele.serial_number + ' 项还未填写相应检查数据', { type: 'div' });
							check = false
							break;
						}
            if(isWrite){
              $.toast(num +'项还未填写相应检查记录', { type: 'div' });
              return false;;
            }
						if (ele.is_photograph && ele.images.length === 0) {
							$.toast(ele.serial_number + ' 项缺少图片', { type: 'div' });
							check = false;
							break;
						}          
             console.log(JSON.stringify(details))
						// 找到有图片最大的索引
						if (ele.images.length) {
							maxIndex = i;
						}
					}
					if (!check) return;
					netStatus = plus.networkinfo.getCurrentType(); // 获取网络状态
					// 有无网络
					if (netStatus > 1) {// 有网
						if (maxIndex === 0) { // 没上传图片,直接提交
							handleSubmit(details)
							handleSave2Local(details); // 本地保存一份
						} else {
							$.each(details, function(i, ele) {
								if (ele.images.length) {
									(function(item, n) {
										upload(item.images[0], function(savePath) {
											console.log(savePath)
											item.uploadImagePath = savePath
											if (n === maxIndex) { // 开始提交
												handleSubmit(details);
												handleSave2Local(details); // 本地保存一份
											}
										});
									})(ele, i);
								}
							});
						}
					} else { // 保存到本地
						$.toast('网络状况不佳，将自动为你保存到草稿箱', { type: 'div' })
						$.later(function(){
							handleSave2Local(details, function() {
								// 更新前一个页面的状态
								var opener = cv.opener();
								$.fire(opener, 'refreshList', {
									id: itemId,
									status: 2
								});
								cv.close();
							});
						}, 1500);
					}
					console.log(details)
				});
				
				// 全部折叠
				document.getElementById('fold').addEventListener('tap', function() {
					if (detailVM.isExpand) {
						$('.mui-collapse').each(function() {
							this.classList.remove('mui-active');
						});
						detailVM.isExpand = false;
					} else {
						$('.mui-collapse').each(function() {
							this.classList.add('mui-active');
						});
						detailVM.isExpand = true;
					}
				});
				
				function save(cb) {
					console.log('保存本地...')
					var details = JSON.parse(JSON.stringify(detailVM.checkDetails))
					$.each(details, function(i, ele) {
            if(ele.data_record){
             var qid = 'item' + ele.serial_number;
             var dom = document.getElementById(qid)
             ele.data_record = dom.innerText.replace(/\s/g,"");
            }						
            if(ele.standard_value_type===4){
              ele.standard_value=ele.standard_value.join(';')
            }
					});
					var hasCheckAll = details.every(function(ele) {
						return ele.status !== '';
					})
					if (!hasCheckAll) {
						$.toast('您还有未检查项，请稍后来处理', { type: 'div' })
					}
					$.later(function() {
						if (cb && typeof cb === 'function') {
							handleSave2Local(details, cb);
						} else {
							handleSave2Local(details);
						}
					}, hasCheckAll ? 0 : 1500)
				}
				
				// 保存
				document.getElementById('save').addEventListener('tap', function() {
					save(function() {
						var details = JSON.parse(JSON.stringify(detailVM.checkDetails))
						$.each(details, function(i, ele) {
              if(ele.data_record){
                var qid = 'item' + ele.serial_number;
                var dom = document.getElementById(qid);
                ele.data_record = dom.innerText;
              }
							
						});
						var allChecked = details.every(function(ele) {
							return ele.status !== ''
						})
						// 更新前一个页面的状态
						var opener = cv.opener();
						$.fire(opener, 'refreshList', {
							id: itemId,
							status: allChecked ? 2 : 1,
							details: details
						});
						updateListData(); // 更新列表页状态
						cv.close();
					});
				});
				$.back = function() {
					var btn = ['否', '是'];
					 $.confirm('您有未保存的内容，是否保存到本地？', '温馨提示', btn, function(e){
						if (e.index === 1){
							var details = JSON.parse(JSON.stringify(detailVM.checkDetails))
							$.each(details, function(i, ele) {
                if(ele.data_record){
                  var qid = 'item' + ele.serial_number;
                  var dom = document.getElementById(qid)
                  console.log(dom.innerText)
                  ele.data_record = dom.innerText.replace(/\s/g,"");
                }								
							});
							save(function() {
								var allChecked = details.every(function(ele) {
									return ele.status !== ''
								})
								// 更新前一个页面的状态
								var opener = cv.opener();
								$.fire(opener, 'refreshList', {
									id: itemId,
									status: allChecked ? 2 : 1,
									details: details
								})
								updateListData(); // 更新列表页状态
								cv.close();
							});
						} else {
							cv.close();
						}
					}, 'div');
				}
			})(mui);
		</script>
	</body>
</html>
